package com.aqie.haikang.dorm.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author aqie
 * @Date 2021/12/10 16:50
 * @desc
 */
@Data
public class R<T> implements Serializable {
    private int code;
    private boolean success;
    private T data;
    private String msg;

    private R(){
        code = 0;
        msg = "ok";
        success = true;
    }
    private R(T data) {
        this();
        this.data = data;
    }

    private R(int code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
        this.success = code == 0;
    }

    private R(int code, String msg) {
        this(code, null, msg);
    }

    public static <T> R<T> ok(){
        return new R<T>();
    }

    public static <T> R<T> ok(T data){
        return new R<T>(data);
    }

    public static <T> R<T> fail(String msg) {
        return new R<>(400, msg);
    }


}
